<?php
require_once('../db/config.php');
session_start();
$sessionCode = "";
for ($i = 1; $i <= 4; $i++) {
    $sessionCode .= dechex(rand(1, 15));
}
$_SESSION['code'] = $sessionCode;
$im = imagecreate(80, 30);
$black = imagecolorallocate($im, 0, 0, 0);
$gray = imagecolorallocate($im, 200, 200, 200);
$blue = imagecolorallocate($im, 180, 200, 255);
$red = imagecolorallocate($im, 255, 0, 0);
$color = imagecolorallocate($im, rand(125, 150), rand(125, 150), rand(125, 150));
imagefill($im, 0, 0, $blue);
for ($i = 1; $i <= 30; $i++) {
    imageline($im, rand(1, 80), rand(1, 30), rand(1, 80), rand(1, 30), $color);
}
for ($i = 1; $i <= 150; $i++) {
    imagesetpixel($im, rand(1, 80), rand(1, 30), $color);
}
imagestring($im, 6, 10, 8, $sessionCode, $black);
ob_clean();
header("Content-type: image/jpeg");
imagejpeg($im);
